<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title></title>
	</head>
	<body>
		<input type="text" id="txt"> <button onclick="send()">发送</button>
	</body>
</html>

<script type="text/javascript">
	var ws = new WebSocket("ws://localhost:8080/webSocket");
	 
	ws.onopen = function(evt) {
		console.log("Connection open ...");
		ws.send("Hello WebSockets!");
	};
	 
	ws.onmessage = function(evt) {
		console.log("Received Message: " + evt.data);
		//ws.close();
	};
	 
	ws.onclose = function(evt) {
		console.log("Connection closed.");
	};
	
	function send(){
		let txt = document.getElementById("txt").value;
		ws.send(txt);
	}
</script>
